package com.tecniplast.selene.controller;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.tecniplast.selene.pojo.User;

@Controller  
public class CommonController {
	@RequestMapping(value = "/mainpage", method = RequestMethod.POST)
	public String renderMainPage(@RequestParam("username") String username,@RequestParam("password") String password) {
		if("admin".equals(username) && "1".equals(password)){
			 return "main";
		}
		return "error";
	}
	
	@RequestMapping(value = "/main", method = RequestMethod.GET)
    public String main(Model model) {
        return "main";
    }
	
	@RequestMapping(value = "/autoReplyMsg", method = RequestMethod.GET)
	public String renderAutoReplyMsgPage(HttpServletRequest request) {
		return "msg/autoReplyMsg";
	}
	
	@RequestMapping(value = "/demolist", method = RequestMethod.GET)
	public String demoList(Model model) {
		List<User> list = new ArrayList<User>();
		for (int i = 0; i < 15; i++) {
			User user = new User();
			user.setName("name" + i + 1);
			user.setAge(26 + i);
			user.setSex("男");
			user.setBirthday(new Date());
			user.setAddress("XXXXX");
			list.add(user);
		}
        model.addAttribute("list", list);
		return "demo/demo";
	}
	
	@RequestMapping(value = "/testJson", method = RequestMethod.GET)
	public @ResponseBody User testJson() {
		User user = new User();
		user.setName("name1");
		user.setAge(26);
		user.setSex("男");
		user.setBirthday(new Date());
		user.setAddress("XXXXX");
		
		return user;
	}
}
